#include "maqgraphicsview.h"
#include "iostream"

MaQGraphicsView::MaQGraphicsView(QWidget * frame):
    QGraphicsView(frame)
{
    this->fenetreImage = (FenetreImage *)frame;
    this->setAlignment(Qt::AlignCenter);
}

MaQGraphicsView::~MaQGraphicsView()
{
}

void MaQGraphicsView::mousePressEvent(QMouseEvent *event){
    QPointF mousePos = this->mapToScene(event->pos());
    emit mousePressPosChanged(mousePos.toPoint());
}

void MaQGraphicsView::mouseMoveEvent(QMouseEvent *event){
    QPointF mousePos = this->mapToScene(event->pos());
    emit mouseMovePosChanged(mousePos.toPoint());

}

void MaQGraphicsView::mouseReleaseEvent(QMouseEvent *event){
    QPointF mousePos = this->mapToScene(event->pos());
    emit mouseReleasePosChanged(mousePos.toPoint());

}

void MaQGraphicsView::setMaScene(MaQGraphicsScene *scene){
    connect(scene, SIGNAL(sceneRectChanged(QRectF)), SLOT(onSceneRectChanged(QRectF)));
}

 void MaQGraphicsView::onSceneRectChanged(QRectF rect){
    this->updateSceneRect(rect);
    this->adjustSize();
    this->setAlignment(Qt::AlignCenter);
    this->setResizeAnchor(QGraphicsView::AnchorViewCenter);
 }
